home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
XCMD libraries 960603
/
xcmdStrings.h
< prev
next >
Wrap
Text File
|
1996-05-29
|
4KB
|
103 lines
// © Paul B. Beeken, Work In Progress, 1994-5
// Knowledge Software Consulting.
//
// These files are a mindlessly simple wrapper class for the
// basic XCMD operations. Only one instance of the xcmdBase class is
// generated per XCMD call but there may be many instances of the XCMDString
// class. I have used these classes to whip out XCMD/XFCNs within hours of
// receiving the specs. They work great for me but I will always consider
// suggestions.
//
// Please, please, please, in the unlikely event you should use this stuff
// for some commercial application I would appreciate you contacting me. If
// its for your own use, use away. Send email: knowsoft@ios.com
//
// As always: this file is presented as is with no warrantees expressed or implied.
// Swim at your own risk, etc. etc.
#pragma once
#include "xcmdBase.h"
#ifndef __HYPERXCMD__
#include <HyperXCmd.h>
#endif
//
// Strings form a very important basis for information exchange in
// hypercard's xcmds and xfcns. It predates the abstract object hierarchy
// devised for AppleScript. All information is passed using handles to
// null terminated strings. Hypercard is a bit schitzophrenic (as is my spelling)
// though. Many
// of the call back functions require the use of pascal type strings. The
// creation of a special class to handle these objects is an attempt to deal
// with this problem in a transparent way.
//
// N.B. an xcmd base object must be instantiated before any of the member
// functions are called. The xcmdBase object sets up the paramPtr which
// is the vector for the call backs.
//
class xcmdString {
friend class xcmdBase; // has to be our friend for it to set up out paramPtr
private:
static XCmdPtr paramPtr; // allocated when xcmdBase object is instantiated.
short len; // string length
char* str; // storage for the string.
// Bottlenecks for string conversion
StringPtr pStr( void ) const { return StringPtr(str); };
char* cStr( void ) const { return &str[1]; }
public:
xcmdString(); // empty pointer
xcmdString( Handle s, Boolean useHandLen=false ); // most common type.
~xcmdString();
// sometimes we need the string explicitly.
int length( void ) const;
// constructors operators for useful types:
xcmdString( xcmdString& s ); // copy constructor
xcmdString( char* s );
xcmdString( char* s, long n );
xcmdString( StringPtr s );
xcmdString( Boolean v );
xcmdString( double_t v );
xcmdString( unsigned long v );
xcmdString( long v, short nd );
xcmdString( long v );
xcmdString( Point pt );
xcmdString( Rect& rct );
// conditioners
void trimWhiteSpace( void ); // trims any leading or trailing space.
// coersion operators for useful types:
operator Boolean() const; // coerece to a Boolean (string is true or false)
operator Rect() const; // coerce to a Rect structure
operator Point() const; // coerce to a Point
operator long() const; // coerce to a signed long value
operator unsigned long() const; // coerce to an unsigned long value
operator double_t() const; // coerce to an extended value
operator StringPtr() const; // coerce to a pascal string ptr
operator char*() const; // coerce to a c string ptr
operator Handle() const; // coerce to a Handle. n.b. user must dispose if not returned to hc.
// some important operators
long contains( const xcmdString& s2 ) const; // offset of s2 in me (1 based)
xcmdString& operator=( const xcmdString& s2 ); // assignment
xcmdString& operator&=( const xcmdString& s2 ); // append assignment
char operator[]( const int i );
friend
xcmdString operator&( const xcmdString& s1, const xcmdString& s2 ); // catenation
friend
Boolean operator==( const xcmdString& s1, const xcmdString& s2 );
friend
Boolean operator!=( const xcmdString& s1, const xcmdString& s2 );
};